package apis

import (
	"graduate_student/model"
	"graduate_student/pkg/app"
	"graduate_student/pkg/e"

	"github.com/gin-gonic/gin"
	"github.com/unknwon/com"
)

func GetExaminee(c *gin.Context) {
	page := -1
	if arg := c.Query("page"); arg != "" {
		page = com.StrTo(arg).MustInt()
	}
	limit := -1
	if arg := c.Query("limit"); arg != "" {
		limit = com.StrTo(arg).MustInt()
	}
	searchText := ""
	if arg := c.Query("searchText"); arg != "" {
		searchText = arg
	}
	examinee := map[string]interface{}{
		"page":       page,
		"limit":      limit,
		"searchText": searchText,
	}
	err, info, total := model.GetExaminee(examinee)
	if err != nil {
		app.Error(c, e.ERROR, err, err.Error())
		return
	}
	app.OK(c, map[string]interface{}{"value": info, "total": total}, "OK")
}

func UpdateExaminee(c *gin.Context) {
	err, info := model.UpdateExaminee(c)
	if err != nil {
		app.Error(c, e.ERROR, err, err.Error())
		return
	}
	app.OK(c, info, "OK")
}

func DeletExaminee(c *gin.Context) {
	err := model.DeletExaminee(c)
	if err != nil {
		app.Error(c, e.ERROR, err, err.Error())
		return
	}
	app.OK(c, "考生删除成功", "OK")
}

func InsertExaminee(c *gin.Context) {
	err, info := model.InsertExaminee(c)
	if err != nil {
		app.Error(c, e.ERROR, err, err.Error())
		return
	}
	app.OK(c, info, "OK")
}
